import 'package:flutter/material.dart';
import './common_form_item.dart';
import '../utils/common_picker/index.dart';

class CommonSelectFormItem extends StatelessWidget {
  final String label;
  final int value;
  final List<String> options;
  final Function(int) onChange;

  const CommonSelectFormItem({Key key, this.label, this.value, this.options, this.onChange}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CommonFormItem(
      label: label,
      contentBuilder: (context){
        return GestureDetector(
          behavior: HitTestBehavior.translucent,
          onTap: (){
            var result = CommonPicker.showPicker(
              context: context,
              options: options,
              value: value,
            );
            result.then((selectedValue) {
              if (value != selectedValue &&
                  selectedValue != null &&
                  onChange != null) {
                onChange(selectedValue);
              }
            });
          },
          child: Container(
            height: 40.0,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(options[value], style: TextStyle(fontSize: 16.0),),
                Icon(Icons.keyboard_arrow_right),
              ],
            ),
          ),
        );
      },
    );
  }
}